package com.simplefan.system.server.consts;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class SystemLanguageConst {

  private static String language;

  private static String country;

  public static final String getLanguageString(String bundleId, String name) {

    if(language == null || country == null) {
      //load();
    }
    /**
    Locale locale = LocaleHelper.getLocale(language, country);
    
    String value = ResourceBundle.getBundle("i18n." + bundleId, locale).getString(name);
     **/
    return name;
  }
  /**
  private static void load() {
    SAXReader sax = new SAXReader();
    Document doc;
    InputStream inputStream = SystemLanguageConst.class.getResourceAsStream("/setting.xml");
    try {
      doc = sax.build(inputStream);
      List<Element> countryElements = XPath.selectNodes(doc.getRootElement(), "//properties/property[@name='common.locale.country']");
      List<Element> languageElements = XPath.selectNodes(doc.getRootElement(), "//properties/property[@name='common.locale.language']");
      if(countryElements.size() > 0) {
        country = countryElements.get(0).getAttributeValue("value");
        language = languageElements.get(0).getAttributeValue("value");
      }
      inputStream.close();
    }
    catch(JDOMException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    catch(IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

  public static String replaceStringByArray(String key, String [] array) {
    for(String element : array) {
      key = key.replaceFirst("#", element);
    }
    return key;
  }
  **/
}
